Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ElevenLabs API Integration, Enhance Security, and Improve Narrator Functionality #53

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

mgennings
Copy link

Overview

This pull request updates the integration with the ElevenLabs API to reflect the latest changes and enhances the overall functionality of the Narrator project. Significant improvements have been made to both narrator.py and capture.py to ensure compatibility with the new API version and to optimize the performance and readability of the code. Additionally, this pull request introduces significant improvements to the way environment variables and API keys are handled in the Narrator project. By implementing a .env file approach, we enhance the security and maintainability of the application.

Changes Made

  1. Updated ElevenLabs API Integration:

    • Refactored narrator.py to use the new ElevenLabs client instantiation method.
    • Replaced deprecated set_api_key and get_api_key methods with the new ElevenLabs class instantiation.
    • Modified the play_audio function to handle the audio generator correctly, gathering audio data into a bytes-like object before writing it to a file and playing it.
  2. Enhanced narrator.py:

    • Added detailed docstrings and comments to improve code readability and maintenance.
    • Ensured that the OpenAI client uses the correct API key and updated the image analysis to handle responses accurately.
    • Improved error handling and logging for better debugging and reliability.
  3. Optimized capture.py:

    • Ensured the frames folder is created if it doesn't exist.
    • Updated the webcam initialization check and added a wait time for the camera to adjust light levels.
    • Adjusted the image resizing logic to improve performance before saving the frame.
    • Added detailed print statements and comments for clarity and debugging purposes.
  4. Enhanced Security:

    • Updated narrator.py to load API keys and other sensitive information from a .env file using the python-dotenv package.
    • Modified requirements.txt to include the python-dotenv package.
    • Revised the README file to provide clear instructions on setting up and using the .env file for managing environment variables.

Benefits

  • Compatibility: The code is now compatible with the latest ElevenLabs API, ensuring continued functionality.
  • Performance: Optimized image processing and audio generation for better performance.
  • Readability: Enhanced code readability and maintainability through detailed comments and improved structure.
  • Security: The .env file method prevents sensitive keys from being hard-coded into the script or inadvertently pushed to the repository.
  • Convenience: Developers can easily set up their environment by updating a single file.
  • Flexibility: This approach simplifies the process of changing and managing API keys without altering the main codebase.

Additional Notes

  • The .env file is included in .gitignore to ensure that personal API keys are kept private.
  • Instructions in the README have been updated to guide new users through the process of setting up their .env file.

Closing Previous Pull Request

The previous pull request titled "Enhance Security: Implement .env for API Keys #44" will be closed as the changes in this new pull request supersede the previous updates and provide a more comprehensive solution.

Looking forward to feedback and suggestions on these enhancements.

mgennings and others added 4 commits January 9, 2024 11:33
…ates

This commit addresses changes made to update the ElevenLabs API version as per pull request cbh123#51 (Update narrator.py to reflect API updates cbh123#51 - cbh123#51). The following changes have been made:

narrator.py:
- Updated the ElevenLabs client instantiation to the new API format.
- Removed the deprecated `set_api_key` and `get_api_key` methods and replaced them with the `ElevenLabs` class instantiation.
- Modified the `play_audio` function to handle the audio generator properly by collecting the audio data into a bytes-like object before writing it to a file and playing it.
- Added detailed docstrings and comments for better understanding and maintenance of the code.
- Ensured that the OpenAI client uses the correct API key and updated the image analysis to handle responses accurately.

capture.py:
- Ensured the frames folder is created if it doesn't exist.
- Updated the webcam initialization check and added a wait time for the camera to adjust light levels.
- Adjusted the image resizing logic to improve performance before saving the frame.
- Added detailed print statements and comments for clarity and debugging purposes.

These changes ensure compatibility with the latest ElevenLabs API and improve the overall robustness and readability of the code.
@mgennings
Copy link
Author

@cbh123 this is the only working branch as of right now.

@treckstar
Copy link

treckstar commented Jul 24, 2024

@mgennings Confirmed this does work for me! Thank you for sharing this! Was using python 3.12.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants